chcp 65001
@ECHO 先把每个文件都编译一遍，这样做是为了万一检测到有一部分文件没改变，可以不再编译，下次直接用o
mkdir tmp
call emcc webgl.c -c -o ./tmp/webgl.o
call emcc main.c -c -o ./tmp/main.o
mkdir out
copy moon.png out\
@ECHO 链接出结果 wasm js 和html
@ECHO 这下面第一行以后全是为了减小尺寸的
call emcc ./tmp/webgl.o ./tmp/main.o --js-library .\library_js.js  -o ./out/t0.html -lGL ^
-sTEXTDECODER=2 -sSUPPORT_ERRNO=0 -sFILESYSTEM=0 -sMINIMAL_RUNTIME=2 -sENVIRONMENT=web ^

call emcc ./tmp/webgl.o ./tmp/main.o --js-library .\library_js.js  -o ./out/t.html -lGL ^
-sTEXTDECODER=2 -sSUPPORT_ERRNO=0 -sFILESYSTEM=0 -sMINIMAL_RUNTIME=2 -sENVIRONMENT=web ^


call emcc ./tmp/webgl.o ./tmp/main.o --js-library .\library_js.js  -o ./out/t_O1.html -lGL ^
-O1 ^
-sTEXTDECODER=2 -sSUPPORT_ERRNO=0 -sFILESYSTEM=0 -sMINIMAL_RUNTIME=2 -sENVIRONMENT=web ^


call emcc ./tmp/webgl.o ./tmp/main.o --js-library .\library_js.js  -o ./out/t_O2.html -lGL ^
-O2 ^
-sTEXTDECODER=2 -sSUPPORT_ERRNO=0 -sFILESYSTEM=0 -sMINIMAL_RUNTIME=2 -sENVIRONMENT=web ^


call emcc ./tmp/webgl.o ./tmp/main.o --js-library .\library_js.js  -o ./out/t_O3.html -lGL ^
-O3 ^
-sTEXTDECODER=2 -sSUPPORT_ERRNO=0 -sFILESYSTEM=0 -sMINIMAL_RUNTIME=2 -sENVIRONMENT=web ^


call emcc ./tmp/webgl.o ./tmp/main.o --js-library .\library_js.js  -o ./out/t_Oz.html -lGL ^
-Oz ^
-sTEXTDECODER=2 -sSUPPORT_ERRNO=0 -sFILESYSTEM=0 -sMINIMAL_RUNTIME=2 -sENVIRONMENT=web ^


call emcc ./tmp/webgl.o ./tmp/main.o --js-library .\library_js.js  -o ./out/t_Oz_c.html -lGL ^
-Oz --closure 1 ^
-sTEXTDECODER=2 -sSUPPORT_ERRNO=0 -sFILESYSTEM=0 -sMINIMAL_RUNTIME=2 -sENVIRONMENT=web ^


@ECHO build done
@REM 这些是对容量不敏感的选项
@REM -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -DMAX_WEBGL_VERSION=2 -sABORTING_MALLOC=0 ^
@REM -sMIN_FIREFOX_VERSION=70  -sMIN_SAFARI_VERSION=130000 -sMIN_IE_VERSION=0x7FFFFFFF -sMIN_EDGE_VERSION=79 -sMIN_CHROME_VERSION=80 ^
@REM -sGL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS=0 -sGL_EXTENSIONS_IN_PREFIXED_FORMAT=0 ^
@REM -sGL_EMULATE_GLES_VERSION_STRING_FORMAT=0 -sGL_POOL_TEMP_BUFFERS=0 -sGL_TRACK_ERRORS=0 -sGL_SUPPORT_SIMPLE_ENABLE_EXTENSIONS=0

@REM --closure 1 闭包优化打开会导致导出符号乱掉，不是以函数为单位了，但是开这个优化 wasm 就不能通用了
@REM -Oz 优化不能开太大，O2 可以开，O3 导出导入符号就被优化了


@REM webgl.o main.o is build output
@REM --js-library .\library_js.js 是需要的js库 实现 load_texture_from_url 方法
@REM -o 输出html文件，如果输出是.js 就只输出 wasm 和 胶水js，如果是html 就输出三个 
@REM -lGL # Link in to WebGL/GLES system library

@REM 非必须


@REM -Oz  # Optimization flag to optimize aggressively for size. (other options -Os, -O3, -O2, -O1, -O0)
@REM 优化标签，很重要，开了优化就会小很多，下面的这些选项也还能影响一些尺寸

@REM --closure 1  # Enable Closure compiler for aggressive JS size minification
@REM -sTEXTDECODER=2   # When marshalling C UTF-8 strings across the JS<->Wasm language boundary, favor smallest generated code size
@REM # rather than performance

@REM -sABORTING_MALLOC=0  # Fine tuning for code size: do not generate code to abort program execution on malloc() failures, that will
@REM # not be interesting here.

@REM 这下面两个需要成对用
@REM -sMINIMAL_RUNTIME=2  # Enable aggressive MINIMAL_RUNTIME mode.
@REM -sENVIRONMENT=web  # The generated build output is only to be expected to be run in a web browser, never in a native CLI shell, or in a web worker.
@REM -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2  # Require WebGL 2 support in target browser, for smallest generated code size. (pass -sMIN_WEBGL_VERSION=1 to dual-target WebGL 1 and WebGL 2)
@REM -DMAX_WEBGL_VERSION=2  # Tell the example code in webgl.c that we are only targeting WebGL 2.
@REM -sSUPPORT_ERRNO=0  # Reduce code size: We do not need libc errno field support in our build output.
@REM -sFILESYSTEM=0  # Reduce code size: We do not need native POSIX filesystem emulation support (Emscripten FS/MEMFS)


@REM 下面的都是针对浏览器兼容
@REM # Choose the oldest browser versions that should be supported. The higher minimum bar you choose, the less
@REM # emulation code may be present for old browser quirks.
@REM append_linker_flags("-sMIN_FIREFOX_VERSION=70")
@REM append_linker_flags("-sMIN_SAFARI_VERSION=130000")
@REM append_linker_flags("-sMIN_IE_VERSION=0x7FFFFFFF") # Do not support Internet Explorer at all (this is the Emscripten default, shown here for posterity)
@REM append_linker_flags("-sMIN_EDGE_VERSION=79") # Require Chromium-based Edge browser
@REM append_linker_flags("-sMIN_CHROME_VERSION=80")

@REM 下面的都是针对关闭一些WEBGL功能
@REM -sGL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS=0  # Reduce WebGL code size: We do not need GLES2 emulation for automatic GL extension enabling
@REM -sGL_EXTENSIONS_IN_PREFIXED_FORMAT=0    # Reduce WebGL code size: We do not need GLES2 emulation for GL extension names
@REM -sGL_EMULATE_GLES_VERSION_STRING_FORMAT=0   # Reduce WebGL code size: No need to specify the GL_VENDOR/GL_RENDERER etc. fields in format required by GLES2 spec.
@REM -sGL_POOL_TEMP_BUFFERS=0   # Reduce WebGL code size at the expense of performance (this only has an effect in WebGL 1, practically a no-op here)
@REM # Reduce WebGL code size: WebGL bindings layer should not keep track of certain WebGL
@REM -sGL_TRACK_ERRORS=0  # errors that are only meaningful for C/C++ applications. (good to enable for release when glGetError() is not used, but disable in debug)
@REM # Reduce WebGL code size: do not emit code for extensions that we might not need.



